import jade.core.Agent;
import jade.core.behaviours.*;
import jade.lang.acl.ACLMessage;

public class BaseAgent extends Agent
{
	protected void setup()
	{
		
		System.out.println("Hello. My name is "+getLocalName());
		addBehaviour(new CyclicBehaviour() 
		{
			Crates local = new Crates(2,1,2,3);
			int i=0;
			Long start=0L;
			Long stop=0L;
			String hello="hello";

			public void action() 
			{
				
				ACLMessage msgRx = receive();
				if (msgRx != null) 
				{
					
					if(!(hello.equals(msgRx.getContent())))
					{
						Crates temp=new Crates(msgRx.getContent());
						i++;
                                                if((i%50)==0)
						{
							stop=System.nanoTime();
							System.out.println("Time: "+ ((stop-start)/1000000000L));
							start=System.nanoTime();
						}
					}
					else
					{
						start=System.nanoTime();
					}
					ACLMessage msgTx = msgRx.createReply();
					msgTx.setContent(local.toMessage());
					send(msgTx);
				} 
				else 
				{
					block();
				}
			}
		});
	}

	protected void takeDown()
	{
		//Destrucion of agent goes here
	}
}
